<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="电话" prop="telephone">
        <el-input
          v-model="queryParams.telephone"
          placeholder="请输入电话"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="姓名" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="性别" prop="sex">
        <el-select v-model="queryParams.sex" placeholder="请选择性别" clearable size="small">
          <el-option
            v-for="dict in dict.type.sys_user_sex"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="年龄" prop="age">
        <el-input
          v-model="queryParams.age"
          placeholder="请输入年龄"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="开户银行" prop="bankOfDeposit">
        <el-input
          v-model="queryParams.bankOfDeposit"
          placeholder="请输入开户银行"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="银行卡号" prop="bankCardNumber">
        <el-input
          v-model="queryParams.bankCardNumber"
          placeholder="请输入银行卡号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="银行卡开户地" prop="openingBank">
        <el-input
          v-model="queryParams.openingBank"
          placeholder="请输入银行卡开户地"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="电子邮箱" prop="email">
        <el-input
          v-model="queryParams.email"
          placeholder="请输入电子邮箱"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="微信号" prop="wechatNumber">
        <el-input
          v-model="queryParams.wechatNumber"
          placeholder="请输入微信号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="车源id" prop="supplyOfCarsId">-->
<!--        <el-input-->
<!--          v-model="queryParams.supplyOfCarsId"-->
<!--          placeholder="请输入车源id"-->
<!--          clearable-->
<!--          size="small"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="被评价次数" prop="beEvaluated">
        <el-input
          v-model="queryParams.beEvaluated"
          placeholder="请输入被评价次数"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="评价总分" prop="totalEvaluate">
        <el-input
          v-model="queryParams.totalEvaluate"
          placeholder="请输入评价总分"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="司机运输次数" prop="transportNumber">
        <el-input
          v-model="queryParams.transportNumber"
          placeholder="请输入司机运输次数"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="司机家庭住址" prop="homeAdd">
        <el-input
          v-model="queryParams.homeAdd"
          placeholder="请输入司机家庭住址"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['huoyun:info:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['huoyun:info:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['huoyun:info:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['huoyun:info:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="infoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="唯一标识数据表" align="center" prop="id" />
      <el-table-column label="电话" align="center" prop="telephone" />
      <el-table-column label="姓名" align="center" prop="name" />
      <el-table-column label="性别" align="center" prop="sex">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_user_sex" :value="scope.row.sex"/>
        </template>
      </el-table-column>
      <el-table-column label="年龄" align="center" prop="age" />
      <el-table-column label="开户银行" align="center" prop="bankOfDeposit" />
      <el-table-column label="银行卡号" align="center" prop="bankCardNumber" />
      <el-table-column label="银行卡开户地" align="center" prop="openingBank" />
      <el-table-column label="电子邮箱" align="center" prop="email" />
      <el-table-column label="微信号" align="center" prop="wechatNumber" />
<!--      <el-table-column label="车源id" align="center" prop="supplyOfCarsId" />-->
      <el-table-column label="被评价次数" align="center" prop="beEvaluated" />
      <el-table-column label="评价总分" align="center" prop="totalEvaluate" />
      <el-table-column label="司机运输次数" align="center" prop="transportNumber" />
      <el-table-column label="司机家庭住址" align="center" prop="homeAdd" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['huoyun:info:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['huoyun:info:remove']"
          >删除</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-zoom-in"
            @click="handleList(scope.row)"
            v-hasPermi="['huoyun:info:remove']"
          >查看</el-button>
        </template>
      </el-table-column>
    </el-table>



    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改车主个人信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="电话" prop="telephone">
          <el-input v-model="form.telephone" placeholder="请输入电话" />
        </el-form-item>
        <el-form-item label="姓名" prop="name">
          <el-input v-model="form.name" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="性别">
          <el-radio-group v-model="form.sex">
            <el-radio
              v-for="dict in dict.type.sys_user_sex"
              :key="dict.value"
:label="dict.value"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="年龄" prop="age">
          <el-input v-model="form.age" placeholder="请输入年龄" />
        </el-form-item>
        <el-form-item label="开户银行" prop="bankOfDeposit">
          <el-input v-model="form.bankOfDeposit" placeholder="请输入开户银行" />
        </el-form-item>
        <el-form-item label="银行卡号" prop="bankCardNumber">
          <el-input v-model="form.bankCardNumber" placeholder="请输入银行卡号" />
        </el-form-item>
        <el-form-item label="银行卡开户地" prop="openingBank">
          <el-input v-model="form.openingBank" placeholder="请输入银行卡开户地" />
        </el-form-item>
        <el-form-item label="电子邮箱" prop="email">
          <el-input v-model="form.email" placeholder="请输入电子邮箱" />
        </el-form-item>
        <el-form-item label="微信号" prop="wechatNumber">
          <el-input v-model="form.wechatNumber" placeholder="请输入微信号" />
        </el-form-item>
<!--        <el-form-item label="车源id" prop="supplyOfCarsId">-->
<!--          <el-input v-model="form.supplyOfCarsId" placeholder="请输入车源id" />-->
<!--        </el-form-item>-->
        <el-form-item label="被评价次数" prop="beEvaluated">
          <el-input v-model="form.beEvaluated" placeholder="请输入被评价次数" />
        </el-form-item>
        <el-form-item label="评价总分" prop="totalEvaluate">
          <el-input v-model="form.totalEvaluate" placeholder="请输入评价总分" />
        </el-form-item>
        <el-form-item label="司机运输次数" prop="transportNumber">
          <el-input v-model="form.transportNumber" placeholder="请输入司机运输次数" />
        </el-form-item>
        <el-form-item label="司机家庭住址" prop="homeAdd">
          <el-input v-model="form.homeAdd" placeholder="请输入司机家庭住址" />
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <el-dialog :title="title" :visible.sync="info" width="800px" append-to-body>
    <el-form :model="queryParams" ref="form" label-width="80px">
      <el-col :span="12">
        <el-form-item label="司机会员号" label-width="100px" prop="driverMid">
          <el-input
            v-model="queryParams.driverMid"
            placeholder="请输入司机会员号"
            clearable
            size="mini"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="车牌号" label-width="100px" prop="plateNo">
          <el-input
            v-model="queryParams.plateNo"
            placeholder="请输入车牌号"
            clearable
            size="mini"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="货物种类" label-width="100px" prop="goodsType">
          <el-input
            v-model="queryParams.goodsType"
            placeholder="请输入货物种类"
            clearable
            size="mini"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="起始地" label-width="100px" prop="startAddress">
          <el-input
            v-model="queryParams.startAddress"
            placeholder="请输入起始地"
            clearable
            size="mini"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="目的地" label-width="100px" prop="endAddress">
          <el-input
            v-model="queryParams.endAddress"
            placeholder="请输入目的地"
            clearable
            size="mini"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="里程" label-width="100px" prop="miliage">
          <el-input
            v-model="queryParams.miliage"
            placeholder="请输入里程"
            clearable
            size="mini"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="运输合同号" label-width="100px" prop="transprotContractNumber">
          <el-input
            v-model="queryParams.transprotContractNumber"
            placeholder="请输入运输合同号"
            clearable
            size="mini"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="司机姓名" label-width="100px" prop="driverName">
          <el-input
            v-model="queryParams.driverName"
            placeholder="请输入司机姓名"
            clearable
            size="mini"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="状态" label-width="100px">
          <el-radio-group v-model="queryParams.status" size="mini">
            <el-radio
              v-for="dict in dict.type.waybill_info_status"
              :key="dict.value"
              :label="dict.value"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="运输方式" label-width="100px" prop="transportMethods">
          <el-input
            v-model="queryParams.transportMethods"
            placeholder="请输入运输方式"
            clearable
            size="mini"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="客户运单号" label-width="100px" prop="clientTransportNumber">
          <el-input
            v-model="queryParams.clientTransportNumber"
            placeholder="请输入客户运单号"
            clearable
            size="mini"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="总价" label-width="100px" prop="totalPrice">
          <el-input
            v-model="queryParams.totalPrice"
            placeholder="请输入总价"
            clearable
            size="mini"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="发货人姓名" label-width="100px" prop="consignorName">
          <el-input
            v-model="queryParams.consignorName"
            placeholder="请输入发货人姓名"
            clearable
            size="mini"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
      </el-col>
    </el-form>

      <div v-show="showSource">
        <hr>
        <el-row :gutter="20">
          <el-col :span="24"><div>车主拥有的车源</div></el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="4"><div class="grid-content bg-purple right">出发地点:</div></el-col>
          <el-col :span="8"><div class="grid-content bg-purple">{{CarInfo.startAddress}}</div></el-col>
          <el-col :span="4"><div class="grid-content bg-purple right">到达地点:</div></el-col>
          <el-col :span="8"><div class="grid-content bg-purple">{{CarInfo.endAddress}}</div></el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="4"><div class="grid-content bg-purple right">车牌:</div></el-col>
          <el-col :span="8"><div class="grid-content bg-purple">{{CarInfo.plateNo}}</div></el-col>
          <el-col :span="4"><div class="grid-content bg-purple right">车型:</div></el-col>
          <el-col :span="8"><div class="grid-content bg-purple">{{CarInfo.carStyle}}</div></el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="4"><div class="grid-content bg-purple right">车长:</div></el-col>
          <el-col :span="8"><div class="grid-content bg-purple">{{CarInfo.carLength}}</div></el-col>
          <el-col :span="4"><div class="grid-content bg-purple right">载重:</div></el-col>
          <el-col :span="8"><div class="grid-content bg-purple">{{CarInfo.loadWeight}}</div></el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="4"><div class="grid-content bg-purple right">所属:</div></el-col>
          <el-col :span="8"><div class="grid-content bg-purple">{{CarInfo.type}}</div></el-col>
        </el-row>
      </div>

    </el-dialog>
  </div>
</template>

<script>
import { listInfo, getInfo, delInfo, addInfo, updateInfo, getCarInfo} from "@/api/person/driver";

export default {
  name: "Person",
  dicts: ['sys_user_sex'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 车主个人信息表格数据
      infoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否显示车源信息
      showSource: true,
      //处理信息的弹窗
      info:false,
      // 车主详细信息
      message: {},
      //车源信息
      CarInfo: {},
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        telephone: null,
        name: null,
        sex: null,
        age: null,
        bankOfDeposit: null,
        bankCardNumber: null,
        openingBank: null,
        email: null,
        wechatNumber: null,
        supplyOfCarsId: null,
        beEvaluated: null,
        totalEvaluate: null,
        transportNumber: null,
        homeAdd: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        telephone: [
          { required: true, message: "电话不能为空", trigger: "blur" }
        ],
        name: [
          { required: true, message: "姓名不能为空", trigger: "blur" }
        ],
        sex: [
          { required: true, message: "性别不能为空", trigger: "blur" }
        ],
        age: [
          { required: true, message: "年龄不能为空", trigger: "blur" }
        ],
        bankOfDeposit: [
          { required: true, message: "开户银行不能为空", trigger: "blur" }
        ],
        bankCardNumber: [
          { required: true, message: "银行卡号不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询车主个人信息列表 */
    getList() {
      this.loading = true;
      listInfo(this.queryParams).then(response => {
        this.infoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        telephone: null,
        name: null,
        sex: "0",
        age: null,
        bankOfDeposit: null,
        bankCardNumber: null,
        openingBank: null,
        email: null,
        wechatNumber: null,
        supplyOfCarsId: null,
        beEvaluated: null,
        totalEvaluate: null,
        transportNumber: null,
        homeAdd: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加车主个人信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getInfo(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改车主个人信息";
      });
    },
    /** 跳转到车主个人信息详情页面，查看车主信息和车源信息 */
    handleList(row) {
      this.$router.push({path: "/service_data/driverDetail", query:{id:row.id}})
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateInfo(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addInfo(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除车主个人信息编号为"' + ids + '"的数据项？').then(function() {
        return delInfo(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('huoyun/info/export', {
        ...this.queryParams
      }, `info_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>

<style scoped>
.el-row {
  margin-bottom: 20px;
}
.el-col {
  border-radius: 4px;
}
.el-col div {
  line-height: 36px;
  font-size: 18px;
}
.right{
  text-align: right;
}
.bg-purple-dark {
  /*background: #99a9bf;*/
}
.bg-purple {
  /*background: #d3dce6;*/
}
.bg-purple-light {
  background: #e5e9f2;
}
.grid-content {
  border-radius: 4px;
  min-height: 36px;
}
.row-bg {
  padding: 10px 0;
  background-color: #f9fafc;
}
</style>
